import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/core/utils/log_util.dart';
import 'package:enterprise_v6_app/app/core/values/dimens.dart';
import 'package:enterprise_v6_app/app/data/entities/application/get_dict_all_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/role_personnel_entity.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

/// description: 自定义底部弹窗 选择器
/// @Param [dataList] 选择器数据
/// @Param [onConfirm] 确认回调
class CustomBottomSheet<T> extends StatelessWidget {
  const CustomBottomSheet({
    required this.dataList,
    required this.onConfirm,
    super.key,
    this.showValue = '',
  });

  /// 选择器数据
  final List<T> dataList;

  /// 确认回调
  final Function(T value) onConfirm;

  ///列表上显示的字段
  final String? showValue;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 58.w + 57.w * dataList.length,
      child: Column(
        children: [
          Expanded(
              child: SingleChildScrollView(
            child: Column(
                children: dataList.map((item) {
              String name = '';
              if (showValue != '' && item is Map) {
                name = item[showValue].toString();
              }else if(item.runtimeType == RolePersonnelEntity) {
                name = (item as RolePersonnelEntity).getShowName().toString();
              } else if(item.runtimeType == GetDictAllEntity) {
                name = (item as GetDictAllEntity).getShowName().toString();
              }
              else {
                name = item.toString();
              }
              return Column(
                children: [
                  Container(
                      height: 56.w,
                      width: AppDimens.sw,
                      alignment: Alignment.center,
                      child: Text(
                        name,
                        style: TextStyle(fontSize: 18.sp),
                      )),
                  Divider(
                    height: 1.w,
                    thickness: 1.w,
                    indent: 1.w,
                    endIndent: 1.w,
                    color: const Color(0xFFE7EAFF),
                  )
                ],
              ).clickOnce(() {
                Navigator.pop(context);
                AppLogger.devLog('选择的值为：${item.toString()}');
                onConfirm(item);
              });
            }).toList()),
          )),
          Container(
            height: 8.w,
            width: AppDimens.sw,
            color: const Color(0xFFF2F2F2),
          ),
          Container(
              height: 50.w,
              width: AppDimens.sw,
              alignment: Alignment.center,
              child: Text(
                '取消',
                style: TextStyle(fontSize: 18.sp),
              )).clickOnce(Get.back),
        ],
      ),
    );
  }
}
